<?php
header('content-type:text/html;charset=utf-8');
$host = "localhost";
$user = "root";
$password = "";
$db = "library";


$mysqli = new mysqli($host, $user, $password, $db); //实例化mysqli对象，连接mysql数据库
if ($mysqli->connect_errno) {
    die($mysqli->connect_error);
}
$mysqli->set_charset('utf8');
$sql = "SELECT * FROM book WHERE bookname =? ";
$mysqli_stmt = $mysqli->prepare($sql);
$bookname = $_POST['bookname'];
$mysqli_stmt->bind_param('s', $bookname);


$query = "SELECT * FROM book WHERE bookname = '$bookname'"; 
$result = mysqli_query($mysqli, $query); //如果结果集中有数据，则用户名已存在 
if(mysqli_num_rows($result) > 0) { 
    if ($mysqli_stmt->execute()) {
        //bind_result() 绑定结果集中的值到变量
        $mysqli_stmt->bind_result($number,$bookname,$aythor);
        //遍历结果集
        while ($mysqli_stmt->fetch()) {
            echo '编号:' . $number;
            echo '<br/>书名: ' . $bookname;
            echo "<br/>作者：".$aythor;
            echo "<html><br/><a href='find.html'>返回查找</a></html>";
        }
        }
 } 
else {
    echo "<script>alert('没有这本书');window.location.href='find.html'</script>"; 
    
}






//释放结果集
$mysqli_stmt->free_result();
$mysqli_stmt->close();
$mysqli->close();
?>